<template>
	<view class="box-mian">

		<view v-for="(item,index) in sendList" :key="index" class="m-20 bg-white bb p-20 br-6 shadow-1">
			<view class="flex ac sb">
				<view class="flex">
					<view>
						<image class="br-100p" :src="item.avatar" mode="aspectFill" style="width: 80rpx;height: 80rpx;">
						</image>
					</view>
					<view class="ml-10 mt-5">
						<view>
							<text class="fw fs-30">{{item.name || ''}}</text>
							<text class="ml-10 mr-10">/</text>
							<text class="fs-24 c-666">{{item.position || ''}}</text>
							<text v-if="item.is_real == 2" class="iconfont-yjgs c-999">&#xe6eb;</text>
							<text v-if="item.is_real == 1" class="iconfont-yjgs ml-10"
								style="color: #00009E;">&#xe6eb;</text>
						</view>
						<view class="c-999 mt-5 fs-24 line-1">
							{{item.company_name || ''}}
						</view>
					</view>
				</view>
				<view v-if="item.status == 1" class="box-fast" style="background-color: #1BA035;color: white;">
					审核通过
				</view>
				<view v-if="item.status == 2" class="box-fast" style="background-color: #FBC017;color: white;">
					审核中
				</view>
				<view v-if="item.status == 3" class="box-fast" style="background-color: #FD201C;color: white;">
					审核驳回
				</view>
				<view v-if="item.status == 4" class="box-fast" style="background-color: #666;color: white;">
					已下架
				</view>
			</view>
			<view class="mt-10" style="margin-left: 90rpx;">
				<view v-if="item.remark" class="mb-20">
					<text class="fw  c-red">驳回:{{item.remark || ''}}</text>
				</view>
				<view class="flex ac">
					<view v-if="item.type == 2" class="box-xq">
						需求
					</view>
					<view v-else class="box-xq"
						style="background-color: #FFE7E6;color: #D22C25;border: 1rpx solid #D22C25;">
						供应
					</view>
					<view class="fw fs-32 ml-10">
						{{item.title || ''}}
					</view>
				</view>
				<view class="mt-10 ">
					<u-read-more toggle :showHeight='140' textIndent='0em'>
						<view>
							<text class="fs-28">
								{{item.content}}
							</text>
						</view>
					</u-read-more>
				</view>
				<view v-if="item.images" class="mt-20 flex ww">
					<view @click="$timer.preView($timer.strToArr($timer.ensureUrl(item.images)),_index)"
						v-for="(obj,_index) in $timer.strToArr($timer.ensureUrl(item.images))" :key="_index"
						class="mb-5 mr-15">
						<image class="br-6" style="height: 160rpx;width: 160rpx;" :src="obj" mode="aspectFill">
						</image>
					</view>
				</view>
				<view class="flex ac">
					<view class="mr-50">
						<text class="fs-24 c-999">{{$timer.formatTime(item.create_time) || ''}}</text>
					</view>
					<view class="ml-50">
						<text class="iconfont icon-pinglun3"></text>
						<text class="ml-5 fs-24">{{item.comment_num || 0}}</text>
					</view>
					<view class="ml-50">
						<text class="iconfont icon-shoucang2"></text>
						<text class="ml-5 fs-24">{{item.follow_num || 0}}</text>
					</view>
					<view class="ml-50">
						<text class="iconfont icon-dianzan1"></text>
						<text class="ml-5 fs-24">{{item.like_num || 0}}</text>
					</view>
					<view @click="extendClick(item)" class="ml-50 box-moreM">
						<text class="iconfont icon-gengduo1"></text>
					</view>
				</view>
			</view>
		</view>


		<!-- 供需对接 扩展 -->
		<u-action-sheet @select='sheetSelect' cancelText='取消' round='12' @close='sheetClose' closeOnClickOverlay
			safeAreaInsetBottom :actions="sheetList" :show="sheetShow"></u-action-sheet>
		<!-- end -->


		<!-- 空数据站位 -->
		<emptyPage v-if="sendList.length == 0" style="margin-top: 0rpx;margin-bottom: 20rpx;">
		</emptyPage>
		<!-- end -->

		<uni-load-more v-if="sendList.length > 0" :status="status" />

	</view>
</template>

<script>
	import emptyPage from '@/pages/extend/components/emptyPage.vue'
	import {
		cardCardInfoList,
		cardCardInfoUserList,
		cardCardInfoDelete
	} from '@/api/extend.js'
	export default {
		components: {
			emptyPage
		},
		data() {
			return {
				sheetShow: false,
				currentItem: {},
				status: 'loading', // more loading noMore
				sheetList: [{
						name: '删除',
					},
					{
						name: '编辑',
					},
					{
						name: '下架',
					},
				],
				sendList: [],
				sendPage: {
					current_page: 1,
				}
			}
		},
		onLoad() {
			uni.$on('sendNeedRefer',() =>{
				this.sendPage.current_page = 1;
				this.sendList = [];
				this.cardCardInfoListFunc(); // 供需发布列表
			})
			this.cardCardInfoListFunc(); // 供需发布列表
		},
		onReachBottom() {
			if (this.status == 'noMore') return;
			this.sendPage.current_page++;
			this.cardCardInfoListFunc(); // 供需发布列表
		},
		methods: {
			sheetSelect(e) {
				if (e.name == '删除') {
					uni.showModal({
						content: '确定要删除吗？',
						success: (res) => {
							if (res.confirm) {
								cardCardInfoDelete({
									id: this.currentItem.id,
									type: 0
								}).then(res => {
									if (res.status == 200) {
										this.sendPage.current_page = 1;
										this.sendList = [];
										this.cardCardInfoListFunc(); // 供需发布列表
									}
									uni.showToast({
										title: res.message,
										icon: 'none',
										duration: 4000
									})
								})
							}
						}
					})
					return;
				}

				if (e.name == '下架') {
					cardCardInfoDelete({
						id: this.currentItem.id,
						type: 2
					}).then(res => {
						if (res.status == 200) {
							this.sendPage.current_page = 1;
							this.sendList = [];
							this.cardCardInfoListFunc(); // 供需发布列表
						}
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 4000
						})
					})
					return;
				}

				if (e.name == '上架') {
					cardCardInfoDelete({
						id: this.currentItem.id,
						type: 1
					}).then(res => {
						if (res.status == 200) {
							this.sendPage.current_page = 1;
							this.sendList = [];
							this.cardCardInfoListFunc(); // 供需发布列表
						}
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 4000
						})
					})
					return;
				}


				if (e.name == '编辑') {
					uni.navigateTo({
						url: '/pages/extend/connection/send_need?id=' + this.currentItem.id
					})
				}
			},
			sheetClose() {
				this.sheetShow = false;
			},
			extendClick(item) {

				const statusMap = {
					1: [{
							name: '编辑'
						}, {
							name: '删除'
						},
						{
							name: '下架'
						}
					],
					2: [{
						name: '删除'
					}],
					3: [{
						name: '编辑'
					}, {
						name: '删除'
					}],
					4: [{
							name: '编辑'
						}, {
							name: '删除'
						},
						{
							name: '上架'
						}
					]
				};

				if (statusMap.hasOwnProperty(item.status)) {
					this.sheetList = statusMap[item.status];
				} else {
					// 处理未定义的状态
					this.sheetList = [];
				}

				this.sheetShow = true;
				this.currentItem = item

			},
			cardCardInfoListFunc() {
				cardCardInfoUserList({
					type: '',
					industry: '',
					keyword: '',
					limit: 6,
					page: this.sendPage.current_page
				}).then(res => {
					let data = res.data.data;
					this.sendPage.current_page = res.data.current_page;
					if (data.length < 6) {
						this.status = 'noMore'
					} else {
						this.status = 'more'
					}
					this.sendList = [...this.sendList, ...data];
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.box-xq {
		border-radius: 6rpx;
		border: 1rpx solid #00009E;
		color: #00009E;
		font-weight: bold;
		text-align: center;
		font-size: 26rpx;
		width: 80rpx;
		height: 40rpx;
		background-color: #F1F1FF;
	}

	.box-moreM {
		text-align: center;
		line-height: 40rpx;
		width: 60rpx;
		height: 40rpx;
		background-color: #F5F5F5;
		border-radius: 6rpx;
	}

	.box-fast {
		text-align: center;
		font-size: 28rpx;
		line-height: 60rpx;
		width: 140rpx;
		height: 60rpx;
		box-sizing: border-box;
		background-color: #E1E1FC;
		color: #00009E;
		font-weight: bold;
		border-radius: 6rpx;
	}

	.box-mian {
		// padding: 20rpx;
	}
</style>